//
//  HMNavigationController.swift
//  Faner_Weibo
//
//  Created by 范英强 on 16/1/26.
//  Copyright © 2016年 范英强. All rights reserved.
//

import UIKit

class HMNavigationController: UINavigationController,UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.interactivePopGestureRecognizer?.delegate = self

    }

    override func pushViewController(viewController: UIViewController, animated: Bool) {

        if childViewControllers.count != 0{
            var title: String = "返回"
            
            //当push到第一个字控制器的时候 左侧按钮显示上个控制器的名字
            //以后都是显示返回
            
            if childViewControllers.count == 1 {
                title = viewControllers.first?.title ?? title
                viewController.hidesBottomBarWhenPushed = true
            }
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(imgName: "navigationbar_back_withtext", title: title, target: self, action: "back")
        }
        
        
        super.pushViewController(viewController, animated: animated)
        
    }
    
    @objc private func back(){
        popViewControllerAnimated(true)
    }

}

extension HMNavigationController{
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        
      return  childViewControllers.count != 1
    
    }
}
